package cn.winwintech.Incense.util;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;

public class OssClientHelper extends OSSClient {

	public OssClientHelper(String endpoint, String accessKeyId, String secretAccessKey) {
		super(endpoint, accessKeyId, secretAccessKey);
	}

	public static final String endpoint = "oss-cn-beijing-internal.aliyuncs.com";
	public static final String endpoint2 = "oss-cn-beijing.aliyuncs.com";
	private static final String imgEndpoint = "img-cn-beijing.aliyuncs.com";
	private static final String accessKeyId = "M72BQYj7yYQ79DNY";
	private static final String accessKeySecret = "DxUBniLEEZ3XkeBPuzJ5pUDYvM3AYG";
	private static OssClientHelper helper = null;
	public static final String BUCKETNAME = "chen-xiang-suyuan-bucket2";

	// Create a new OSSClient instance
	public static OssClientHelper shareClient() {
		if (helper == null) {
			synchronized (OssClientHelper.class) {
				if (helper == null) {
					helper = new OssClientHelper(endpoint, accessKeyId, accessKeySecret);
					helper.setClientConfig(helper.getClientConfiguration());
				}
			}
		}
		return helper;
	}

	private void setClientConfig(ClientConfiguration conf) {
		conf.setMaxConnections(100);
		conf.setConnectionTimeout(5000);
		conf.setMaxErrorRetry(3);
		conf.setSocketTimeout(2000);
	}

	public String generateThumbnailUrl(String osskey, int w, int h) {
		return "http://" + BUCKETNAME + "." + imgEndpoint + "/" + osskey;
	}

	public String generateThumbnailUrl(String key) {
		return generateThumbnailUrl(key, 100, 100);
	}

}
